/*
 * HomeProfesor.java
 *
 * Created on 01/10/2009, 11:57:04 PM
 */

package Interfaz;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.Border;
/**
 *
 * @author usuario
 */

@SuppressWarnings("serial")
public class principal extends JFrame {	
	protected JLabel banner;
	static int ide_usuario;
    @SuppressWarnings("static-access")
	public principal(int tipo, int ide) {
    	super("Portal academico");
    	JPanel Inge=new JPanel();
    	Inge.setLayout(new BorderLayout()); // Para que la imagen se agrande
    	JLabel label = new JLabel();
    	Inge.add(label, BorderLayout.CENTER);
    	label.setIcon (new ImageIcon("Logo.png"));
    	add(label);
    	
    	addWindowListener(new BasicWindowMonitor()); 
    	
    	Image icono = Toolkit.getDefaultToolkit().getImage("Logo.png");
    	setIconImage(icono);
		setExtendedState(JFrame.MAXIMIZED_BOTH);
		this.setMinimumSize(new Dimension(500,500));
		
    	
    	usuario usu = usuario.getInstance();
    	usu.ide_usuario=ide;
    	usu.tip_usuario=tipo;
		initComponents(tipo, ide);
		
    }
    public String sayHello() {
    	
    	Scanner input;
    	String result = "+",ress;
		try {
			input = new Scanner( new File( "config.ini" ) );
	    	for (int i = 0; i < 4; i++)
	    	{ ress = input.next();
	    	result = result + "+" + ress;
	    	}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

    	return result;
    }
    private void initComponents(int tipo, int ide) {
    	setSize(500, 500);
    	setExtendedState(JFrame.MAXIMIZED_BOTH);
    	
        try{
            File f = new File ("cabecera.jpg");
            BufferedImage tmpImagen = ImageIO.read (f);
            HacerFondo fondo = new HacerFondo(tmpImagen);
            ((JComponent) this.getContentPane()).setBorder(fondo);
          }catch (Exception ex){ex.printStackTrace();}
    	
    	banner = new JLabel ();
    	banner.setIcon (new ImageIcon("cabecera.jpg"));
    	
    	
        BorderLayout df=new BorderLayout();
        JPanel bannerPanel = new JPanel(df);
        bannerPanel.add(banner, BorderLayout.NORTH);
        add(bannerPanel, BorderLayout.NORTH);
        
        JTabbedPane tab=new JTabbedPane();
        tab.setSize(600, 500);
        //tab.addTab("HomeProfesor", new Administrador());
        //tab.addTab("HomeProfesor", new HomeProfesor());
        
        add(tab, BorderLayout.CENTER);
        
    }
    
 public static String convertByteArrayToString(byte[] arra) {    
	//byte[] byteArray = new byte[] {87, 79, 87, 46, 46, 46};
	String value = new String(arra);
	System.out.println("probando--"+arra.toString()+"="+value);
	return value;
}
 public static  byte[] convertStringToByteArray(String stringToConvert) {
     //String stringToConvert = "hola mundoo";
     byte[] theByteArray = stringToConvert.getBytes();
     System.out.println(theByteArray.length);
     return theByteArray;
 }
 public static int intLen(int a){
	 int b=0;
	 for (;a>10;a=a/10){
		 b++;
	 }
	 return b;
 }
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
            	principal p=new principal(1,2);
            	p.setVisible(true);            	
            
            }
        });
    }
    public class HacerFondo implements Border{
 	   private BufferedImage mImagen = null;

 	   public HacerFondo(BufferedImage pImagen){
 	   mImagen = pImagen;
 	   }

 	   public void paintBorder(Component c, Graphics g, int x,int y,int width,int height){

 	   if(mImagen != null){
 		   g.drawImage(mImagen,0,0,width,height,null);
 	   }
 	   }

 	   public Insets getBorderInsets (Component c){
 	      return new Insets(0,0,0,0);
 	   }

 	   public boolean isBorderOpaque(){
 	      return true;
 	   }
 	}
    public class BasicWindowMonitor extends WindowAdapter { 
   	 
  	  public void windowClosing(WindowEvent e) { 
  	    Window w = e.getWindow(); 
  	    w.setVisible(false); 
  	    w.dispose(); 
  	    System.exit(0); 
  	  } 
  	}
    
}